﻿Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Reflection
Imports System.ComponentModel.Design.Serialization
Imports System

Friend Class RangeCheckPropertiesConverter
   Inherits ExpandableObjectConverter

   Public Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, _
                                       ByVal culture As Globalization.CultureInfo, _
                                       ByVal value As Object, _
                                       ByVal destinationType As Type) As Object


      If destinationType Is GetType(String) Then
         Return ""
      End If

      If destinationType Is GetType(InstanceDescriptor) AndAlso TypeOf value Is RangeCheckProperties Then
         Dim ci As ConstructorInfo
         ci = GetType(RangeCheckProperties). _
              GetConstructor(BindingFlags.NonPublic Or BindingFlags.Instance, _
                             Nothing, _
                             CallingConventions.ExplicitThis, _
                             New Type() {GetType(NumericInputBox)}, _
                             Nothing)
         Dim rcp As RangeCheckProperties = CType(value, RangeCheckProperties)

         Dim ID As New InstanceDescriptor(ci, New Object() {rcp.Parent})
         Return ID
      End If

      Return MyBase.ConvertTo(context, culture, value, destinationType)
   End Function


   Public Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, _
                                          ByVal destinationType As System.Type) As Boolean
      If destinationType Is GetType(InstanceDescriptor) Then
         Return True
      End If

      If destinationType Is GetType(String) Then Return True

      Return MyBase.CanConvertTo(context, destinationType)
   End Function

End Class

